using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms.Design;
using System.Windows.Forms;
using System.ComponentModel;
using Microsoft.Xna.Framework;

namespace Ferpect.GameComponents.Design
{
    /// <summary>
    /// This class is a designer for the ViewControl class.  Since ViewControl implements
    /// ICustomTypeDescriptor to get the attributes of its TComponent parameter type, you
    /// must use the ViewDocumentDesignerAttribute on the TComponent instance to specify
    /// the root designer for the ViewControl class.
    /// 
    /// The implementation of ICustomTypeDescriptor will replace the DesignerAttributes
    /// from TComponent with new ones based on the types specified in the ViewDocumentDesigner
    /// and ViewControlDesigner attributes.
    /// </summary>
    public class ViewDocumentDesigner<TComponent> : DocumentDesigner
        where TComponent : IComponent, IDrawable, IGameComponent, new()
    {
        // The Control instance that is instantiated on the design surface.
        private ViewControl<TComponent> viewControl;

        public ViewDocumentDesigner()
        {
        }

        /// <summary>
        /// This method is invoked as a component is being added to the designer container.
        /// Here, the designer adds an instance of TComponent to the design surface inside
        /// the INestedContainer.  The TComponent is expected to have a DesignTimeVisibleAttribute
        /// with argument "false" to keep it from appearing in either the properties window
        /// or the component tray.
        /// </summary>
        /// <param name="component">The ViewControl instance associated with this designer.</param>
        public override void Initialize(System.ComponentModel.IComponent component)
        {
            this.viewControl = (ViewControl<TComponent>)component;

            base.Initialize(component);
        }

        /// <summary>
        /// This override does not call the base override because the base assumes the
        /// object being designed is a Control-based component.  As such, it will add
        /// Control-specific extender properties that we do not want to appear on our
        /// TComponent instance. Specific filtering for a view control can be obtained
        /// by overriding this method.
        /// </summary>
        protected override void PostFilterProperties(System.Collections.IDictionary properties)
        {
        }

        /// <summary>
        /// This override does not call the base override because the base assumes the
        /// object being designed is a Control-based component.  As such, it will add
        /// Control-specific extender properties that we do not want to appear on our
        /// TComponent instance. Specific filtering for a view control can be obtained
        /// by overriding this method.
        /// </summary>
        protected override void PreFilterProperties(System.Collections.IDictionary properties)
        {
        }

        /// <summary>
        /// This override ensures that the default behavior does not allow the
        /// ViewControl to be manually resized.  This can obviously be overridden
        /// for special cases.
        /// </summary>
        public override SelectionRules SelectionRules
        {
            get
            {
                return SelectionRules.Visible;
            }
        }
    }
}
